from tools.listNode import ListNode, listToNode, nodeToList


def deleteDuplicates(head):
    """
    :type nums: List[int]
    :rtype: List[List[int]]
    """
    if not head:
        return None
    s = set()
    res = ListNode()
    res.next = head
    s.add(head.val)
    while head and head.next:
        nxt = head.next
        if head.next.val in s:
            head.next = nxt.next
        else:
            s.add(head.next.val)
            head = head.next
    return res.next


print(nodeToList(deleteDuplicates(listToNode([1, 1, 2]))))  # [1, 2]
print(nodeToList(deleteDuplicates(listToNode([1, 1, 2, 3, 3, 3, 3, 3, 3, 3]))))  # [1, 2, 3, 4]
print(nodeToList(deleteDuplicates(listToNode([]))))  # [1, 2, 3, 4]
